<?php

class CamposAdminController extends \BaseController {

	public function __construct(){
		
		$roles=array(
				'redactor'=>4,
				'admin'=>1,
				'usuario'=>'2',
				'admin.torneos'=>3
		);
		
		//permisos
		$rolesCampos=array($roles['admin.torneos'],$roles['admin']);
		
		$this->beforeFilter('roles:'.implode($rolesCampos,'-'));
	}
	
	
	/**
	 * Display a listing of noticiasadmins
	 *
	 * @return Response
	 */
	public function index()
	{
		$campos = Campo::all();
		
		return View::make('contents.admin.campos.index', compact('campos'));
	}

	/**
	 * Show the form for creating a new noticiasadmin
	 *
	 * @return Response
	 */
	public function create()
	{
		return View::make('contents.admin.campos.create');
	}

	/**
	 * Store a newly created noticiasadmin in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		$validator = Validator::make($data = Input::all(), Campo::$rules);

		if ($validator->fails())
		{
			return Redirect::back()->withErrors($validator)->withInput();
		}

		$campo = new Campo();
		$campo->fill($data);
		$campo->save();
		

		return Redirect::route('admin.campos.index');
	}

	/**
	 * Display the specified noticiasadmin.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		$campo = Campo::findOrFail($id);

		return View::make('contents.admin.campos.show', compact('campo'));
	}

	/**
	 * Show the form for editing the specified noticiasadmin.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		$campo = Campo::find($id);

		return View::make('contents.admin.campos.edit', compact('campo'));
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		$campo = Campo::findOrFail($id);

		$validator = Validator::make($data = Input::all(), Campo::$rules);

		if ($validator->fails())
		{
			return Redirect::back()->withErrors($validator)->withInput();
		}

		$campo->update($data);

		return Redirect::route('admin.campos.index');
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		Campo::destroy($id);

		return Redirect::route('admin.campos.index');
	}

}